﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

/// <summary>
/// TLinkmanGive 的摘要说明
/// </summary>
public class TLinkmanGive : TData
{
    //常量
    const string CTableName = "t_linkman_give";
    const string CKeyName = "manid";
    //与数据表字段对应的变量
    private string FManID;
    private string FGiveLvl;
    private string FGiveType;
    private string FGiveMag;
    private int FGiveQty;
    private string FGiveExpl;
    private DateTime FGiveBDate;
    private DateTime FGiveEDate;
    private string FPassMan;
    private DateTime FPassTime;
    private int FStatus;
    private string FInMan;
    private DateTime FInTime;
    private int FIId;

    //分页显示使用
    public System.Data.SqlClient.SqlDataReader RResults;
    public int RowCounts;
    public int PageCounts;
    const int PageSize = 30;

    public TLinkmanGive()
    {
        FTableName = CTableName;
        FKeyName = CKeyName;
    }

    public TLinkmanGive(string manid)
    {
        FTableName = CTableName;
        FKeyName = CKeyName;
        FKeyValue = manid;
    }

    //根据manid获得记录值
    public override void Select()
    {
        string strSql = GetSelectString();
        TSqlDB oDB = new TSqlDB(strSql);
        if (!oDB.EOF)
        {
            FManID = oDB["manid"].ToString();
            FGiveLvl = oDB["givelvl"].ToString();
            FGiveType = oDB["givetype"].ToString();
            FGiveMag = oDB["givemag"].ToString();
            FGiveQty = oDB["giveqty"].ToInt();
            FGiveExpl = oDB["giveexpl"].ToString();
            FGiveBDate = oDB["givebdate"].ToDateTime();
            FGiveEDate = oDB["giveedate"].ToDateTime();
            FPassMan = oDB["passman"].ToString();
            FPassTime = oDB["passtime"].ToDateTime();
            FStatus = oDB["status"].ToInt();
            FInMan = oDB["inman"].ToString();
            FInTime = oDB["intime"].ToDateTime();
            FIId = oDB["iid"].ToInt();
        }
        oDB.Free();
    }

    //插入新记录。
    public void Insert()
    {
        string ExSql = "'" + FManID + "','" + FGiveLvl + "','" + FGiveType + "','" + FGiveMag + "'," + FGiveQty.ToString() + ",'" + FGiveExpl + "','" + FGiveBDate.ToString("yyyy-M-d") + "','" + FGiveEDate.ToString("yyyy-M-d") + "',";
        ExSql += "'" + FPassMan + "','" + FPassTime.ToString("yyyy-M-d") + "',";
        ExSql += FStatus.ToString() + ",'" + FInMan + "',getdate()";
        base.Insert(ExSql);
    }

    //更新记录,全记录。
    public void Update()
    {
        string ExSql = "givelvl='" + FGiveLvl + "',givetype='" + FGiveType + "',givemag='" + FGiveMag + "',giveqty=" + FGiveQty.ToString() + ",giveexpl='" + FGiveExpl + "',givebdate='" + FGiveBDate.ToString("yyyy-M-d") + "',giveedate='" + FGiveEDate.ToString("yyyy-M-d") + "',";
        ExSql += "passman='" + FPassMan + "',passtime='" + FPassTime.ToString("yyyy-M-d") + "',";
        ExSql += "status=" + FStatus.ToString() + ",intime=getdate()";
        base.Update(ExSql);
    }

    //更新记录。
    public void Update2()
    {
        string ExSql = "givelvl='" + FGiveLvl + "',givetype='" + FGiveType + "',givemag='" + FGiveMag + "',giveqty=" + FGiveQty.ToString() + ",giveexpl='" + FGiveExpl + "',givebdate='" + FGiveBDate.ToString("yyyy-M-d") + "',giveedate='" + FGiveEDate.ToString("yyyy-M-d") + "',";
        ExSql += "status=" + FStatus.ToString() + ",inman='" + FInMan + "',intime=getdate()";
        base.Update(ExSql);
    }

    //改变状态,0=未验证,1=已通过验证
    public void Update_status()
    {
        string ExSql = "status=" + FStatus.ToString(); ;
        base.Update(ExSql);
    }

    //静态，可以不用创建对象即可调用。
    public static void DeleteByID(string sID)
    {
        TData.DeleteByID(sID, CTableName, CKeyName);
    }

    //分页显示
    public void GetPage(int PageNum,int stat)
    {
        int iStartRow, iStopRow;

        iStartRow = (PageNum - 1) * PageSize + 1;
        iStopRow = PageNum * PageSize;

        TSqlDBProc oProc = new TSqlDBProc("ms_GetCheckList", 0);
        oProc.ms_GetCheckList(iStartRow, iStopRow, stat);

        RResults = oProc.FDataReader;
    }

    //生成pagebar
    public string GenPagebar(int PageNum,int stat)
    {
        string result = "<div class=\"pagebox\">";

        CountPage(stat);

        if (PageCounts > 1)
        {
            if (PageNum == 1)//第一页
            {
                result += "<span class=\"pagebox_num_nonce\"><a>首页</a></span>";
                for (int i = 1; i <= PageCounts; i++)
                {
                    if (i != PageNum)
                    {
                        result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('" + i.ToString() + "')\">" + i.ToString() + "</a></span>";
                    }
                    else
                    {
                        result += "<span class=\"pagebox_num_nonce\"><a>" + i.ToString() + "</a></span>";
                    }
                }
                result += "<span class=\"pagebox_pre_nolink\">上一页</span>";
                result += "<span class=\"pagebox_next\"><a onclick=\"getlinkmans('2')\">下一页</a></span>";
                result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('" + PageCounts.ToString() + "')\">尾页</a></span>";
            }
            if ((PageNum > 1) && (PageNum < PageCounts))
            {
                result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('1')\">首页</a></span>";
                for (int i = 1; i <= PageCounts; i++)
                {
                    if (i != PageNum)
                    {
                        result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('" + i.ToString() + "')\">" + i.ToString() + "</a></span>";
                    }
                    else
                    {
                        result += "<span class=\"pagebox_num_nonce\"><a>" + i.ToString() + "</a></span>";
                    }
                }
                result += "<span class=\"pagebox_pre\"><a onclick=\"getlinkmans('" + (PageNum - 1).ToString() + "')\">上一页</a></span>";
                result += "<span class=\"pagebox_next\"><a onclick=\"getlinkmans('" + (PageNum + 1).ToString() + "')\">下一页</a></span>";
                result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('" + PageCounts.ToString() + "')\">尾页</a></span>";
            }

            if (PageNum == PageCounts)//最后一页
            {
                result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('1')\">首页</a></span>";
                for (int i = 1; i <= PageCounts; i++)
                {
                    if (i != PageNum)
                    {
                        result += "<span class=\"pagebox_num\"><a onclick=\"getlinkmans('" + i.ToString() + "')\">" + i.ToString() + "</a></span>";
                    }
                    else
                    {
                        result += "<span class=\"pagebox_num_nonce\"><a>" + i.ToString() + "</a></span>";
                    }
                }
                result += "<span class=\"pagebox_pre\"><a onclick=\"getlinkmans('" + (PageCounts - 1).ToString() + "')\">上一页</a></span>";
                result += "<span class=\"pagebox_next_nolink\">下一页</span>";
                result += "<span class=\"pagebox_num_nonce\"><a>尾页</a></span>";
            }
        }
        else
        {
            result += "<span class=\"pagebox_num_nonce\"><a>首页</a></span>";
            result += "<span class=\"pagebox_num_nonce\"><a>1</a></span>";
            result += "<span class=\"pagebox_pre_nolink\">上一页</span>";
            result += "<span class=\"pagebox_next_nolink\">下一页</span>";
            result += "<span class=\"pagebox_num_nonce\"><a>尾页</a></span>";
        }

        result += "<span style=\"padding-top: 4px;\">&nbsp;(每页显示" + PageSize.ToString() + "行)</span></div>";

        return result;
    }

    //计算页数
    private void CountPage(int stat)
    {
        string sSql = "select count(*) from vw_givelist where status=" + stat.ToString();
        RowCounts = TSqlDB.ExecuteScalar(sSql);

        if (RowCounts % PageSize == 0)  //余数为零
        {
            PageCounts = RowCounts / PageSize;
        }
        else
        {
            PageCounts = (int)(RowCounts / PageSize) + 1;
        }
    }

    public string ManID
    {
        get
        {
            return FManID;
        }
        set
        {
            FManID = value;
        }
    }

    public string GiveLvl
    {
        get
        {
            return FGiveLvl;
        }
        set
        {
            FGiveLvl = value;
        }
    }

    public string GiveType
    {
        get
        {
            return FGiveType;
        }
        set
        {
            FGiveType = value;
        }
    }

    public string GiveMag
    {
        get
        {
            return FGiveMag;
        }
        set
        {
            FGiveMag = value;
        }
    }

    public int GiveQty
    {
        get
        {
            return FGiveQty;
        }
        set
        {
            FGiveQty = value;
        }
    }

    public string GiveExpl
    {
        get
        {
            return FGiveExpl;
        }
        set
        {
            FGiveExpl = value;
        }
    }

    public DateTime GiveBDate
    {
        get
        {
            return FGiveBDate;
        }
        set
        {
            FGiveBDate = value;
        }
    }

    public DateTime GiveEDate
    {
        get
        {
            return FGiveEDate;
        }
        set
        {
            FGiveEDate = value;
        }
    }

    public string PassMan
    {
        get
        {
            return FPassMan;
        }
        set
        {
            FPassMan = value;
        }
    }

    public DateTime PassTime
    {
        get
        {
            return FPassTime;
        }
        set
        {
            FPassTime = value;
        }
    }

    public int Status
    {
        get
        {
            return FStatus;
        }
        set
        {
            FStatus = value;
        }
    }

    public string InMan
    {
        get
        {
            return FInMan;
        }
        set
        {
            FInMan = value;
        }
    }

    public DateTime InTime
    {
        get
        {
            return FInTime;
        }
        set
        {
            FInTime = value;
        }
    }

    public int IId
    {
        get
        {
            return FIId;
        }
        set
        {
            FIId = value;
        }
    }
}
